<@_sysApp id=id><#assign a=object/></@_sysApp>
<form method="post" action="sysApp/save.do?callbackType=closeCurrent&navTabId=sysApp/list" class="pageForm required-validate" onsubmit="return validateCallback(this, navTabAjaxDone);">
    <input type="hidden" name="_csrf" value="<@_csrfToken admin=true/>"/>
    <div class="formBar">
        <ul>
            <li><button type="submit" class="buttonActive"><@t.page 'button.save'/></button></li>
            <li><button type="button" class="button close"><@t.page 'button.close'/></button></li>
        </ul>
    </div>
    <div class="pageFormContent" layoutH="50">
        <input name="id" type="hidden" value="${id!}" />
        <input name="appKey" type="hidden" value="${(a.appKey)!getUUID()}"/>
    <#if !a?has_content>
        <input name="appSecret" type="hidden" value="${getUUID()}"/>
        <dl class="nowrap">
            <dt><@t.page 'channel'/>:</dt>
            <dd><input class="required" name="channel" type="text" size="30" value="${(a.channel)!}"/></dd>
        </dl>
    <#else>
        <dl class="nowrap">
            <dt><@t.page 'channel'/>:</dt>
            <dd>${(a.channel)!}</dd>
        </dl>
    </#if>
        <dl class="nowrap">
            <dt><@t.page 'expiry_minutes'/>:</dt>
            <dd><input name="expiryMinutes" type="number" size="30" value="${(a.expiryMinutes)!}" min="1"/></dd>
        </dl>
        <fieldset class="ownsAllRight">
            <legend><@t.page 'app.interface'/></legend>
            <ul id="authorizedApis" class="treeFolder treeCheck expand">
                <li>
                    <a href="javascript:;" onclick="return false;"><@t.page 'app.all_interface'/></a>
                    <ul>
                        <li>
                            <a data-id="0" href="javascript:;" onclick="return false;"><@t.page 'app.directive'/></a>
                            <ul></ul>
                        </li>
                        <li>
                            <a data-id="1" href="javascript:;" onclick="return false;"><@t.page 'app.method'/></a>
                            <ul></ul>
                        </li>
                        <li>
                            <a data-id="2" href="javascript:;" onclick="return false;"><@t.page 'app.app_directive'/></a>
                            <ul></ul>
                        </li>
                    </ul>
                </li>
            </ul>
        </fieldset>
    </div>
<script>
var apisArray=['/api/directives','/api/methods','/api/apis'];
var authorizedApis = '${(a.authorizedApis)!}'.split(",");
var i=0;
for (api in apisArray){
    getApi(api);
}
function getApi(api){
    $.ajax({
        url:'${base}'+apisArray[api],
        type: 'GET',
        contentType:'application/json; charset=UTF-8',
        dataType: 'json',
        success: function (dataList) {
            $(dataList).each(function(index,data){
                var style='';
                if('true'==data.needAppToken){
                    $('#authorizedApis a[data-id='+api+']',navTab.getCurrentPanel()).next().append('<li><a tname="apis" tvalue="'+data.name+'">'+data.name+'</a></li>');
                }
            });
            if(++i==apisArray.length){
                $("#authorizedApis", navTab.getCurrentPanel()).addClass('tree').jTree();
                for(authorizedApi in authorizedApis){
                    $("input[type=checkbox][value="+authorizedApis[authorizedApi]+"]", navTab.getCurrentPanel()).click();
                }
            }
        }
    });
}
</script>
</form>